package 数据结构.章节09;


/**
 * @author 挚爱之夕
 * @date 2021/10/11 - 10 - 11 - 23:21
 * @Description: 数据结构.章节09
 * @Version: 1.0
 */
public class _154_删除单链表的某个节点 {
    public static void main(String[] args) {
        int[] a = new int[]{1,2,3,4,5};
        ListNode head = new ListNode(a[0]);
        ListNode p = head;
        for (int i = 1; i < a.length; i++) {
            p.next = new ListNode(a[i]);
            p = p.next;
        }
        p = head;
        while(p != null){
            System.out.print(p.val+"\t");
            p = p.next;
        }
        System.out.println("+++++++++++");
        p = head.next;
        deleteNode(p);
        p = head;
        while(p != null){
            System.out.print(p.val+"\t");
            p = p.next;
        }

    }
    private static class ListNode{
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    private static boolean deleteNode(ListNode listNode){
        if(listNode.next==null){
            return false;
        }
        listNode.val = listNode.next.val;
        listNode.next = listNode.next.next;
        return true;
    }
}
